home *** CD-ROM | disk | FTP | other *** search
- /************************************
- *
- * file: SimpleOutFileStuff.c
- *
- * Program: SimpleOutMovies
- * This program creates a movie by spooling in PICTs from a folder
- * and adding adding them one at a time to the movie. When all PICTs have
- * been processed a sound track is added if one is present.
- *
- * This program uses the sequence compression commands
- * which make smaller movie files by only saving
- * the changes between frames
- *
- * In this file I have collected all routines having to do with
- * file I/O
- *
- * By Guillermo A. Ortiz
- * April 1991
- *
- * Apple Macintosh Developer Technical Support
- *
- * Copyright © 1989-1991 Apple Computer, Inc.
- * All rights reserved.
- *
- *************************************/
-
-
- #include <Types.h>
- #include <QuickDraw.h>
- #include <ToolUtils.h>
- #include <Events.h>
- #include <Controls.h>
- #include <Windows.h>
- #include <Dialogs.h>
- #include <Menus.h>
- #include <Desk.h>
- #include <SegLoad.h>
- #include <Files.h>
- #include <OSEvents.h>
- #include <Traps.h>
- #include <Fonts.h>
- #include <OSUtils.h>
- #include <Resources.h>
- #include <Memory.h>
- #include <Packages.h>
- #include <Lists.h>
- #include <Files.h>
- #include <errors.h>
-
- /* STR# resources */
- #define rStrMisc 256
-
- /* Resource ID's for Standard File Dialog */
- #define rGetDirectoryDLOG 1002
-
- /* resources for the sound alert */
-
- #define kHasSound 1
- #define rSoundAlert 128
-
- #define CurDirStore 0x398 /* DirID of current directory [LONG] */
- #define firstTime -1 /* the first time our hook is called, it is passed a -1 */
-
- OSErr OpenOneFile(PicHandle p, short index);
-
- Handle MyGetSF2(void);
- OSErr MyGetSF(FSSpec *);
-
- /* for SetDirectory sample */
- long MyCurDir;
- Boolean CurDirValid;
-
- /* some globals */
- SFReply reply; /* used in all SF samples */
- Point gLocation = {0x40,0x40};
- SFTypeList typeList = {'FSSD'}; /* gimmie sound files */
-
- /******************************************************************************/
- pascal short MyGetDirHook(item, dPtr)
- short item;
- DialogPtr dPtr;
- {
- /* Equates for the itmes that I've added */
- #define getDirButton 11
- #define getDirNowButton 12
- #define getDirMessage 13
-
- Str255 messageTitle;
- short kind;
- Handle h;
- Rect r;
-
- switch (item) {
- case firstTime:
-
- /* Read in the prompt string from the resource fork, and initialize */
- /* CurDirValid to FALSE. */
-
- GetIndString(&messageTitle,rStrMisc,3);
- GetDItem(dPtr,getDirMessage,&kind,&h,&r);
- SetIText(h,&messageTitle);
- CurDirValid = false;
- break;
- case getDirButton:
- if (reply.fType != 0) {
- MyCurDir = reply.fType;
- CurDirValid = true;
- return(getCancel);
- };
- break;
- case getDirNowButton:
- MyCurDir = *(long *)CurDirStore;
- CurDirValid = true;
- return(getCancel);
- };
- return(item); /* By default, return the item passed to us. */
- };
-
-
- pascal Boolean FoldersOnly(p)
- ParmBlkPtr p;
- {
- /* Normally, folders are ALWAYS shown, and aren't even passed to */
- /* this file filter for judgement. Under such circumstances, it is */
- /* only necessary to blindly return TRUE (allow no files whatsoever). */
- /* However, Standard File is not documented in such a manner, and */
- /* this feature may not be TRUE in the future. Therefore, we DO check */
- /* to see if the entry passed to us describes a file or a directory. */
-
- if ((p->fileParam.ioFlAttrib & 0x10) != 0)
- return(false);
- return(true);
- };
-
-
- void GetDirectory()
- {
-
- SFPGetFile(gLocation, /* location */
- "\pSpace for Rent", /* vestigial string */
- FoldersOnly, /* fileFilter */
- -1, /* numtypes; -1 means all */
- &typeList, /* array to types to show */
- MyGetDirHook, /* dlgHook */
- &reply, /* record for returned values */
- rGetDirectoryDLOG,
- nil);
-
- };
-
- /* here we get each picture one at the time.
- This function selects the file in sequential order in the
- selected folder and reads in the PICT. The PICT is stored in
- a handle provided by the caller.
-
- When the folder contains files that are not PICT the routine returns with
- no error but sets the size of the pict handle to 10 signaling the calling
- party that althought the file is there it does not contain a picture.
-
- Writing this was great fun.
- */
- OSErr OpenOneFile(PicHandle p, short index)
- {
- CInfoPBRec pb;
- Str255 s;
- OSErr err;
- long fLength;
- short FRefNum;
-
- if (CurDirValid) { /* selection of folder went ok */
- pb.hFileInfo.ioCompletion = nil;
- pb.hFileInfo.ioNamePtr = &s;
- pb.hFileInfo.ioVRefNum = reply.vRefNum;
- pb.hFileInfo.ioFDirIndex = index;
- pb.hFileInfo.ioDirID = MyCurDir;
- if ( ! (err = PBGetCatInfo(&pb, false)) ) {
- if (pb.hFileInfo.ioFlFndrInfo.fdType != 'PICT')
- SetHandleSize ((Handle) p, 10);/* we'll use this to signify that the file is the wrong type */
- else { /* make sure to process only PICTs */
- pb.hFileInfo.ioCompletion = nil;
- pb.hFileInfo.ioNamePtr = &s;
- pb.hFileInfo.ioVRefNum = reply.vRefNum;
- pb.hFileInfo.filler1 = 1; /* I only need to read */
- pb.hFileInfo.ioFDirIndex = 0; /* These three fields */
- pb.hFileInfo.ioFlAttrib = pb.hFileInfo.filler2 = 0; /* should make for ioMisc */
- pb.hFileInfo.ioDirID = MyCurDir;
- if (! (err = PBHOpen ((HParmBlkPtr)&pb, false)) ) {
- FRefNum = pb.hFileInfo.ioFRefNum;
- err = GetEOF(FRefNum, &fLength); /* can't fail */
- fLength -= 512; /* we don't need the file header */
- if ( GetHandleSize((Handle) p) < fLength) /* resize handle */
- SetHandleSize ((Handle) p, fLength);
- if ( ! (err = MemError()) ) { /* problems resizing ? */
- err = SetFPos(FRefNum, fsFromStart, 512); /* jump over file header */
- HLock((Handle) p);
- err = FSRead(FRefNum, &fLength, (Ptr)*p);
- HUnlock((Handle) p);
- err = FSClose(FRefNum);
- }
- }
- }
- }
- }
- return err;
- }
-
- /* Here we get the sound resource (we assume only one resource in each file)
- and pass it back to add to the media.
-
- */
-
- Handle MyGetSF2()
-
- {
- Point dlgPos = {100,100};
- short FRefNum, resFNum;
- Handle resH = nil;
- short itemHit;
- Str255 volName;
- short volRef;
-
- if ( (itemHit = Alert(rSoundAlert, nil)) == kHasSound ) { /* make sure user has sound file */
- SFGetFile(dlgPos, "\pSound file:",nil,1,&typeList,nil,&reply);
- if (reply.good) {
- FRefNum = CurResFile();
- GetVol(volName, &volRef);
- SetVol('',reply.vRefNum);
- resFNum = OpenResFile(reply.fName);
- if ( resH = Get1IndResource('snd ',1) ) /* assuming one resource for file */
- DetachResource(resH);
- CloseResFile(resFNum);
- UseResFile(FRefNum);
- SetVol(volName, volRef);
- }
- }
- return resH;
- }
-
- /* The code that adds a sound by reference calls this code in order to get a file where
- the sound data is located; the difference is that here we need to know the offset
- to the data and this makes resources kind of difficult to handle.
- */
- OSErr MyGetSF(mySpec)
- FSSpec *mySpec;
- {
-
- OSErr err;
- Point dlgPos = {100,100};
- short itemHit;
-
- if ( (itemHit = Alert(rSoundAlert, nil)) == kHasSound ) { /* make sure user has sound file */
- SFGetFile(dlgPos, "\pSound file:",nil,1,&typeList,nil,&reply);
- if (reply.good) {
- err = FSMakeFSSpec(reply.vRefNum, 0, (unsigned char *) reply.fName, mySpec);
- }
- }
- else
- err = fnfErr;
-
- return err;
- }